<template>
  <!-- 试题审核对话框 -->
  <div class="container">
    <el-dialog
      title="题目审核"
      :visible="dialogFormVisible"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        label-width="120px"
        label-position="left"
        :model="form"
      >
        <el-form-item prop="chkState" label-position="left">
          <el-radio-group v-model="form.chkState">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="chkRemarks">
          <el-input
            placeholder="请输入审核意见"
            type="textarea"
            v-model="form.chkRemarks"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <!-- 按钮 -->
          <el-row type="flex" justify="center">
            <el-col :span="12">
              <el-button size="medium" @click="closeDialog"> 取消 </el-button>
              <el-button size="medium" type="primary" @click="submit">
                确定
              </el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck, auditOpinions } from '@/api/hmmm/questions.js'
export default {
  name: 'QuestionsCheck',
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      form: {
        chkState: 1,
        chkRemarks: ''
      }
    }
  },
  methods: {
    // 关闭弹窗
    closeDialog () {
      this.form = {
        chkState: '',
        chkRemarks: '',
        id: ''
      }

      // 重置表单
      this.$refs.form.resetFields()

      this.$emit('update:dialogFormVisible', false)
    },
    // 点击确定按钮发起增加学科的请求
    async submit () {
      // form表单校验
      await this.$refs.form.validate()
      console.log(this.id)
      this.form.id = this.id

      await choiceCheck(this.form)
      this.$message.success('操作成功')
      // 关闭页面弹窗
      this.closeDialog()

      // $emit方式调用父组件上的方法

      // 调用父组件上的方法
      this.$parent.choiceList()
    },
    // 在编辑状态下发起获取审核意见的请求
    async getDepartmentInfo () {
      const data = await auditOpinions(this.id)

      console.log(data)
      // this.form = { ...data }
    }
  }
}
</script>

<style scoped lang="less">
.container {
  ::v-deep .el-dialog {
    width: 400px;
    ::v-deep .el-dialog__header {
      padding: 20px 20px 10px;
    }
    .el-dialog__body {
      .el-form {
        .el-form-item--medium {
          margin-bottom: 18px;
          width: 100%;
          .el-radio-group {
            width: 100%;
            line-height: 32px;
            font-size: 14px;
          }
        }
        .el-form-item {
          .el-form-item__content {
            .quill-editor {
              ::v-deep .ql-container {
                height: 200px;
              }
            }
            .el-row {
              width: 100%;
              display: flex;
              .el-col {
                width: 100%;
                display: flex;
                justify-content: flex-end;
              }
            }
          }
        }
      }
    }
  }
}
</style>
